<?php
$baseDir = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
$fontsDir = $baseDir."/vendor/zendframework/zendframework/library/pChart/Fonts";
    
// Chart for CA TTC
if($id == 1) {   
    // Get data
    $data = $budget = array();
    $dataLabel = array();
    foreach($ca as $ca_ttc):
        $orderDateTime = new DateTime($ca_ttc['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = $ca_ttc['ca_ttc'];
        $budget[] = $budgets['cattc'];
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    if(!empty($budget)) $DataSet->AddPoint($budget,"Serie2");
    $DataSet->AddPoint($dataLabel,"Label");
    $DataSet->AddSerie("Serie1");
    if(!empty($budget)) $DataSet->AddSerie("Serie2");
    $DataSet->SetAbsciseLabelSerie("Label");
    $DataSet->SetSerieName("Budget réel","Serie1");     
    if(!empty($budget)) $DataSet->SetSerieName("Budget prévisionnel","Serie2");     
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196); 
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230); 
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,2,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawLegend(905,-5,$DataSet->GetDataDescription(),255,255,255);    
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for CA HT
if($id == 2) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($ca as $ca_ht):
        $orderDateTime = new DateTime($ca_ht['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = $ca_ht['ca_ht'];
        $budget[] = $budgets['caht'];
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    if(!empty($budget)) $DataSet->AddPoint($budget,"Serie2");
    $DataSet->AddPoint($dataLabel,"Label");
    $DataSet->AddSerie("Serie1");
    if(!empty($budget)) $DataSet->AddSerie("Serie2");
    $DataSet->SetAbsciseLabelSerie("Label");
    $DataSet->SetSerieName("Budget réel","Serie1");     
    if(!empty($budget)) $DataSet->SetSerieName("Budget prévisionnel","Serie2");   
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230); 
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,2,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawLegend(905,-5,$DataSet->GetDataDescription(),255,255,255); 
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Taux reduit 1
if($id == 3) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($vtva as $txred1):
        $orderDateTime = new DateTime($txred1['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        if($txred1['taxeRate'] == 5.5) {
            $data[] = ($txred1['ca_ttc'])?$txred1['ca_ttc']:0;
            $dataLabel[] = $orderDate;
        }
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data, "Serie1");
    $DataSet->AddPoint($dataLabel, "Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Taux reduit 2
if($id == 4) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($vtva as $txred2):
        $orderDateTime = new DateTime($txred2['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        if($txred2['taxeRate'] == 7 || $txred2['taxeRate'] == 10) {
            $data[] = ($txred2['ca_ttc'])?$txred2['ca_ttc']:0;
            $dataLabel[] = $orderDate;
        }
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data, "Serie1");
    $DataSet->AddPoint($dataLabel, "Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Taux normal
if($id == 5) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($vtva as $txnorm):
        $orderDateTime = new DateTime($txnorm['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        if($txnorm['taxeRate'] == 19.6 || $txnorm['taxeRate'] == 20) {
            $data[] = ($txnorm['ca_ttc'])?$txnorm['ca_ttc']:0;
            $dataLabel[] = $orderDate;
        }
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data, "Serie1");
    $DataSet->AddPoint($dataLabel, "Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for CB
if($id == 6) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($banque as $bq):
        $orderDateTime = new DateTime($bq['date']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($bq['cb'])?$bq['cb']:0;
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data, "Serie1");
    $DataSet->AddPoint($dataLabel, "Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Cheque
if($id == 7) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($banque as $bq):
        $orderDateTime = new DateTime($bq['date']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($bq['cheque'])?$bq['cheque']:0;
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data, "Serie1");
    $DataSet->AddPoint($dataLabel, "Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Espece
if($id == 8) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($banque as $bq):
        $orderDateTime = new DateTime($bq['date']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($bq['espece'])?$bq['espece']:0;
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data, "Serie1");
    $DataSet->AddPoint($dataLabel, "Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Ticket restaurant
if($id == 9) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($banque as $bq):
        $orderDateTime = new DateTime($bq['date']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($bq['tr'])?$bq['tr']:0;
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data, "Serie1");
    $DataSet->AddPoint($dataLabel, "Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Annulation Caisse
if($id == 13) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($ac as $nbAc):
        $orderDateTime = new DateTime($nbAc['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($nbAc['ac']!=0)?$nbAc['ac']:0;
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    $DataSet->AddPoint($dataLabel,"Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2"); 
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Ecarts caisses
if($id == 14) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($ecDays as $ecDay):
        $ecDateTime = new DateTime($ecDay['date']);
        $ecDate = date_format($ecDateTime, 'd/m/y');
        $data[] = ($ecDay['ec'])?$ecDay['ec']:0;
        $dataLabel[] = $ecDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    $DataSet->AddPoint($dataLabel,"Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2"); 
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230); 
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,2,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Transactions
if($id == 15) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($nbT as $nbTr):
        $orderDateTime = new DateTime($nbTr['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($nbTr['nbTransaction']!=0)?$nbTr['nbTransaction']:0;
        $budget[] = $budgets['nbt'];
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    if(!empty($budget)) $DataSet->AddPoint($budget,"Serie2");
    $DataSet->AddPoint($dataLabel,"Label");
    $DataSet->AddSerie("Serie1");
    if(!empty($budget)) $DataSet->AddSerie("Serie2");
    $DataSet->SetAbsciseLabelSerie("Label");
    $DataSet->SetSerieName("Budget réel","Serie1");     
    if(!empty($budget)) $DataSet->SetSerieName("Budget prévisionnel","Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawLegend(905,-5,$DataSet->GetDataDescription(),255,255,255);
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for TM
if($id == 16) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($tm as $tm_ttc):
        $orderDateTime = new DateTime($tm_ttc['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($tm_ttc['nombre']!=0)?($tm_ttc['valeur']/$tm_ttc['nombre']):0;
        $budget[] = $budgets['cattc']/$budgets['nbt'];
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    if(!empty($budget)) $DataSet->AddPoint($budget,"Serie2");
    $DataSet->AddPoint($dataLabel,"Label");
    $DataSet->AddSerie("Serie1");
    if(!empty($budget)) $DataSet->AddSerie("Serie2");
    $DataSet->SetAbsciseLabelSerie("Label");
    $DataSet->SetSerieName("Budget réel","Serie1");     
    if(!empty($budget)) $DataSet->SetSerieName("Budget prévisionnel","Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230); 
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,2,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawLegend(905,-5,$DataSet->GetDataDescription(),255,255,255);
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Articles
if($id == 17) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($nbA as $nbAr):
        $orderDateTime = new DateTime($nbAr['orderDate']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($nbAr['nbArticle']!=0)?$nbAr['nbArticle']:0;
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    $DataSet->AddPoint($dataLabel,"Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230); 
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Taux prise
if($id == 18) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($nbA as $nbArticle):
        foreach($nbT as $nbTransaction):
            if($nbArticle['orderDate'] == $nbTransaction['orderDate']):
                $orderDateTime = new DateTime($nbArticle['orderDate']);
                $orderDate = date_format($orderDateTime, 'd/m/y');
                $artNb = ($nbArticle['nbArticle']!=0)?$nbArticle['nbArticle']:0;
                $traNb = ($nbTransaction['nbTransaction']!=0)?$nbTransaction['nbTransaction']:0;
                $txp = $artNb/$traNb;
                $data[] = $txp;
                $dataLabel[] = $orderDate;
            endif;
        endforeach;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    $DataSet->AddPoint($dataLabel,"Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2");
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);  
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,2,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for MO
if($id == 19) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($rhdata as $rhd):
        $orderDateTime = new DateTime($rhd['date']);
        $orderDate = date_format($orderDateTime, 'd/m/y');
        $data[] = ($rhd['mo']!=0)?$rhd['mo']:0;
        $dataLabel[] = $orderDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    $DataSet->AddPoint($dataLabel,"Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2"); 
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230);   
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,0,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Repas
if($id == 24) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($repasDays as $repasDay):
        $repasDateTime = new DateTime($repasDay['orderDate']);
        $repasDate = date_format($repasDateTime, 'd/m/y');
        $data[] = ($repasDay['repas'])?$repasDay['repas']:0;
        $dataLabel[] = $repasDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    $DataSet->AddPoint($dataLabel,"Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2"); 
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230); 
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,2,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}

// Chart for Meteo
if($id == 27) {
    // Get data
    $data = array();
    $dataLabel = array();
    foreach($meteoDays as $meteoDay):
        $meteoDateTime = new DateTime($meteoDay['meteoDate']);
        $meteoDate = date_format($meteoDateTime, 'd/m/y');
        $data[] = ($meteoDay['temperature'])?$meteoDay['temperature']:0;
        $dataLabel[] = $meteoDate;
    endforeach;
    
    // Dataset definition
    $DataSet = new pData;
    $DataSet->AddPoint($data,"Serie1");
    $DataSet->AddPoint($dataLabel,"Serie2");
    $DataSet->AddSerie("Serie1");
    $DataSet->SetAbsciseLabelSerie("Serie2"); 
    
    // Initialise the graph  
    $Chart = new pChart(1080,280);  
    $Chart->setColorPalette(0,130,141,196);
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",8);  
    $Chart->setGraphArea(50,30,1050,230); 
    $Chart->drawFilledRoundedRectangle(7,7,693,223,5,255,255,255);  
    $Chart->drawRoundedRectangle(5,5,695,225,5,255,255,255);  
    $Chart->drawGraphArea(255,255,255,TRUE);  
    $Chart->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_START0,150,150,150,TRUE,45,2,TRUE);     
    $Chart->drawGrid(4,TRUE,230,230,230,50);
    
    // Draw the 0 line  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",6);  
    $Chart->drawTreshold(0,143,55,72,TRUE,TRUE);
    
    // Draw the bar graph  
    //$Chart->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);  
    $Chart->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription()); 
    $Chart->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);  

    // Finish the graph  
    $Chart->setFontProperties($fontsDir."/tahoma.ttf",10);  
    $Chart->drawTitle(50,22,"",50,50,50,585);  
    $Chart->Stroke();
}
?>